/*---------------------------------------------------------------------------*/
/*!				\file				main.h
				\date				march 2010
				\author				TNick

				\brief				Main definition file for this application
    
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef		__BILLYBOY_MAIN_INC___
#define		__BILLYBOY_MAIN_INC___

//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */
	
/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

	/// memory allocator
	#define	MALL(msz)		(HeapAlloc(hHeapApp,0,msz))
	/// memory free
	#define	MFREE(pMM)		(HeapFree(hHeapApp,0,pMM))
	/// memory redimensionate
	#define	MREALL(pMM,msz)	(HeapReAlloc(hHeapApp,0,pMM,msz))
	
	/// associate a value with a panel
	#define SETWLINK(hwwW,plll)	(SetWindowLong(hwwW,GWL_USERDATA,(LONG)plll))
	/// retrive panel's associated value
	#define GETWLINK(hwwW)		(GetWindowLong(hwwW,GWL_USERDATA))
	
	#ifdef	DEBUG
		/// debug message using direct text
		#define	DEBUGMSGt(msgtxt)  \
			OutputDebugString(TEXT("\n======================================\n"));\
			OutputDebugString(TEXT(msgtxt))
		/// debug message using pointer
		#define	DEBUGMSG (pmsgtxt) (OutputDebugString(pmsgtxt))
		/// debug message and GetLastError
		#define DEBUGGLE(msgtxt)  \
			dGle = GetLastError(); \
			OutputDebugString(TEXT(msgtxt)); \
			OutputDebugString(TEXT("\nGetLastError returns ")); \
			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
				FORMAT_MESSAGE_FROM_SYSTEM,\
				NULL,dGle,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
				(LPTSTR) &lpDebugMsgBuf,0,NULL); \
			OutputDebugString(lpDebugMsgBuf); \
			LocalFree(lpDebugMsgBuf);
	
	#else
		#define	DEBUGMSGt(msgtxt)	
		#define	DEBUGMSG(pmsgtxt)	
		#define DEBUGGLE(msgtxt)	
	#endif
	
	
	// ID's for main panel
	#define	ID_MAIN_DV			1012
	#define	ID_MAIN_LST_L		1013
	#define	ID_MAIN_LST_R		1014
	
	
	
	
	/// name of main window's class
	#define	CLASSNAME_MAIN		TEXT("BILLYBOY_ClsM")
	/// name of class for divider
	#define	CALSS_DIV			TEXT("BILLYBOY_ClsDv")
	/// initial text for application's main panel
	#define	APPNAME_START		TEXT("BillyBoy")
	#define	APPNAME_START_LEN	(sizeof(TCHAR)*8)
	/// styles for main window
	#define WSEX_MAIN_F         0 // WS_EX_TOPMOST
	/// styles for main window
	#define WS_MAIN_F           (WS_OVERLAPPEDWINDOW)
	/// custom message signaling that separator is moving
	#define	WM_SEP_MOVING		(WM_USER + 101)
	/// message shown by the ABOUT message
	#ifdef	BBLANGUAGE_ROMANIAN
		#define	ABOUT_TEXT		TEXT("  BillyBoy este o aplicatie realizata pentru\n") \
								TEXT("a furniza un mod usor si rapid de ascundere\n") \
								TEXT("a ferestrelor selectate.\n\n") \
								TEXT("Program scris de TNick\n") \
								TEXT("Va rog vizitati http://code.google.com/p/billyboy/\n") \
								TEXT("Licenta: New BSD licence.\n")
	#else
		#define	ABOUT_TEXT		TEXT("  BillyBoy is a small application intended\n") \
								TEXT("to provide you with an easy way to hide\n") \
								TEXT("some panels that you select.\n\n") \
								TEXT("Written by TNick\n") \
								TEXT("Please visit http://code.google.com/p/billyboy/\n") \
								TEXT("Released under New BSD licence.\n")
	#endif
	#ifdef	BBLANGUAGE_ROMANIAN
		/// error text
		#define	ERR_TEXT		TEXT("Eroare")
		/// error telling that the gesture is wrong
		#define	ERR_GEST		TEXT("Gestul trebuie sa fie compus din doua elemente")
		/// error telling thata window has disappeared
		#define	ERR_MISSINGWIN	TEXT("Fereastra nu mai exista")
	#else
		/// error text
		#define	ERR_TEXT		TEXT("Error")
		/// error telling that the gesture is wrong
		#define	ERR_GEST		TEXT("The gesture must have exactly two elements")
		/// error telling thata window has disappeared
		#define	ERR_MISSINGWIN	TEXT("The window no longer exists")
	#endif
	
	
	/// placement of the mouse
	typedef enum _GST_ROW {
		GST_ROW_TL	=	0, /**< top left */
		GST_ROW_TR	=	1,
		GST_ROW_BL	=	2,
		GST_ROW_BR	=	3,
		GST_ROW_INVALID	=100
	} GST_ROW;

	/// width of separator between the two lists
	#define	SEP_SIZE			4
	/// minimum width for main panel
	#define	MIN_WIDTH_MAIN		40
	/// this is the size of the square on the corners of the screen 
	#define	SQUARE_SIZE			10
	/// how often the timer fires
	#define	TIMER_RESOLUTION	100
	/// id of the timer object
	#define	ID_TIMER_GESTURE	1212
	/// number of columns in lists
	#define	LISTCOLS_CNT		2

	
	/// current state of application and managed panels
	typedef enum _WSTATE {
		STATE_UNHIDDEN	=	0,
		STATE_HIDDEN	=	1
	} WSTATE;
	
	/// these are the flags used to control various parts
	typedef enum _APPFL {
		APPFL_SHOWGEST	= 0x00000001, /**< use gesture to show items */
		APPFL_HIDEGEST	= 0x00000002, /**< use gesture to hide items */
		
		APPFL_FLTR_NAME	= 0x00000004, /**< filter windows by name */
		APPFL_FLTR_HID	= 0x00000008, /**< filter windows by ??? */
		APPFL_FLTR_ALTT	= 0x00000010, /**< filter windows by Alt+Tab method */
		APPFL_FLTR_PRNT	= 0x00000020, /**< filter windows by ??? */
		APPFL_FLTR_ICN	= 0x00000040, /**< filter windows by icon */
		
		APPFL_STARTHD	= 0x00000080, /**< start-up hidden */
		APPFL_HIDEME	= 0x00000100, /**< hide application, too */
		APPFL_ONTOP		= 0x00000200, /**< keep app window ontop */
		APPFL_MASK		= 0x000003FF
	} APPFL;
	
	/// structure to describe a shotcut (a letter and one or more of C, A, D)
	typedef struct _SHRC	{
		char	Letter;
		char	Ctrl;
		char	Alt;
		char	Shift;
	} SHRC;

	/// describes the settings for the application
	typedef struct _SETT	{
	
		SHRC		ShowSrg; 		/**< shortcut for showing panels */
		SHRC		HideSrg; 		/**< shortcut for showing panels */
		char		ShowGest[4]; 	/**< gesture for showing panels */
		char		HideGest[4]; 	/**< gesture for hiding panels */
		
		APPFL		Flags;		/**< switches for application */
		unsigned	EpocsToWait;	/**< epocs to wait */
		
		LONG		LsL_ColW[LISTCOLS_CNT];	/**< width of columns on left */
		LONG		LsR_ColW[LISTCOLS_CNT];	/**< width of columns on right */
		LONG		Width_Left;		/**< width of left side */
		
		RECT		rMW;			/**< position and size of main window*/
	} SETT;

/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */
	
	extern	HANDLE		hHeapApp;	/**< handle of memory source */
	extern	HINSTANCE	hInstance;	/**< module handle for exe */
	extern	HWND		hwMain;		/**< main panel */
	extern	HWND		hW_Ls_L;	/**< handle of left list*/
	extern	HWND		hW_Ls_R;	/**< handle of right list*/
	extern	HWND		hWOpts;		/**< gets set when option is visible */
	extern	HHOOK		g_mouseHook;/**< hook for mouse */
	extern	HHOOK		g_keyboardHook; /**< hook for keyboard */
	extern	LONG		cxScreen;	/**< size of the screen (X) */
	extern	LONG		cyScreen;	/**< size of the screen (Y) */
	extern	HFONT		hF_Gen;		/**< font used in all controls */
	extern	HIMAGELIST	hImLst;		/**< image list used all 
						across the application */
	extern	WSTATE		CurrentState;	/**< ststus (visible/not) */
	extern	GST_ROW		GestureStart;	/**< set whenever the mouse touches 
						a corner */
	extern	UINT_PTR	gTimer;		/**< handle of timer */
	extern	unsigned	Epcs;		/**< number of epocs left to wait */
	extern	SETT		AppStgs;	/**< global application settings */

	extern	const TCHAR	AppRegKey[];/**< registry key for our app */
	extern	const TCHAR	AppRegKeyHost[];
	extern	const TCHAR	AppRegKeyName[];

	#ifdef DEBUG
		extern	void* lpDebugMsgBuf;		/**< used with debug messages*/
		extern	DWORD dGle;		/**< used with debug messages*/
	#endif
	
	
/*  DATA    ================================================================ */
//
//
//
//
/*  FUNCTIONS    ----------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
	/// function called at application start-up
	/// \return TRUE if all went ok, FALSE if an error occured
	unsigned	App_Init(void);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function called at application end-up
	void		App_End(void);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function that loads the settings
	void		GetSettings			(
		SETT*		pStg
	);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function that save the settings
	void		SaveSettings		(
		SETT*		pStg
	);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// window procedure for separator window
	LRESULT CALLBACK WP_Div			(HWND hh, UINT mm, WPARAM ww, LPARAM ll);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// window procedure for separator window
	LRESULT CALLBACK WP_Main		(HWND hh, UINT mm, WPARAM ww, LPARAM ll);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// system hook for mouse
	LRESULT CALLBACK MouseProc		(int nCode, WPARAM wParam, LPARAM lParam);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// system hook for keyboard
	LRESULT CALLBACK KeyboardCallback(int nCode, WPARAM wParam, LPARAM lParam);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function to hide selected panels
	void			Do_HideSelected		(void);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function to show selected panels
	void			Do_UnHideSelected	(void);
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
	/// function to scan for panels
	void			RefreshVisList		(void);;
/* ========================================================================= */




/*  FUNCTIONS    =========================================================== */
//
//
//
//
#endif	//	__BILLYBOY_MAIN_INC___

/* ------------------------------------------------------------------------- */
/* ========================================================================= */
